//
//  NSString+LSTSHA_1.m
//  23_加密
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "NSString+LSTSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (LSTSHA_1)

- (NSString *)stringWithSHA_1 {
    // 返回C语言字符串
    const char *cStr = [self UTF8String];
    // 求长度
    CC_LONG len = (CC_LONG)strlen(cStr);
    unsigned char bytes[CC_SHA1_BLOCK_LONG];
    // SHA_1转换
    CC_SHA1(cStr, len, bytes);
    NSMutableString *finalSHA1 = [NSMutableString stringWithCapacity:CC_SHA1_BLOCK_LONG];
    for (int i = 0; i < CC_SHA1_BLOCK_LONG; i++) {
        [finalSHA1 appendFormat:@"%02x", bytes[i]];
    }
    return finalSHA1;
}

@end
